import { handlerHotkeyConfig } from './handleHotkeyConfig.js'
/**
 * 通过setConfig 修改服务的配置信息  wuyax(彭庆凯) 2020-9-17
 * @param {object} config 配置项
 */
import { has } from 'lodash-es'

export function setConfig(config) {
  // license
  if (has(config, 'license.code')) {
    this.licenseServer.code = config.license.code
  }
  // data source
  if (has(config, 'dataSource.type')) {
    this.dataSourceServer.type = config.dataSource.type
  }
  // part
  if ((config, 'part.isDragOpen')) {
    this.partServer.isDragOpen = config.part.isDragOpen
  }
  if ((config, 'page')) {
    this.pageServer.init(config.page)
    app.anovPage.update()
  }
  // actions
  if (Array.isArray(config.actions)) {
    this.actionServer.addActions(config.actions)
  }
  // voice commands
  if (Array.isArray(config.commands)) {
    this.voiceRecognizeServer.addCommands(config.commands)
  }
  // hotkeys
  if (Array.isArray(config.hotkeys)) {
    let hotkeyConfig = handlerHotkeyConfig(config.hotkeys)
    this.hotkeyServer.addHotkeys(hotkeyConfig)
  }
  // env
  if (has(config, 'env')) {
  }
  // panel
  if (has(config, 'panel')) {
    const { panel } = config
    if (has(panel, 'activeTab')) {
      this.panelServer.activeTab(panel.activeTab)
    }
    if (has(panel, 'disableTabs') && panel.disableTabs.length) {
      this.panelServer.disableTabs = panel.disableTabs
    }
    if (has(panel, 'uniqueOpened')) {
      this.panelServer.uniqueOpenBlock = panel.uniqueOpenBlock
    }
    if (has(panel, 'permission')) {
      this.panelServer.updateLicense(panel.permission)
    }
  }
  // voiceFeedback
  if (has(config, 'voiceFeedback')) {
    const { voiceFeedback } = config
    if (has(voiceFeedback, 'thirdConfig')) {
      this.voiceFeedbackServer.callMutation(
        'setThirdConfig',
        voiceFeedback.thirdConfig
      )
    }
    if (has(voiceFeedback, 'synthesisType')) {
      this.voiceFeedbackServer.changeSynthesisType(voiceFeedback.synthesisType)
    }
    if (has(voiceFeedback, 'isStart')) {
      this.voiceFeedbackServer.isStart = voiceFeedback.isStart
    }
  }
  // lightSensor
  if (has(config, 'lightSensor')) {
    const { lightSensor } = config
    if (has(lightSensor, 'isStart')) {
      this.lightSensorServer.isStart = lightSensor.isStart
    }
    if (has(lightSensor, 'isHue')) {
      this.lightSensorServer.isHue = lightSensor.isHue
    }
    if (has(lightSensor, 'isBrightness')) {
      this.lightSensorServer.isBrightness = lightSensor.isBrightness
    }
    if (has(lightSensor, 'intervalTime')) {
      this.lightSensorServer.intervalTime = lightSensor.intervalTime
    }
  }
  // faceRecognize
  if (has(config, 'faceRecognize.isStart')) {
    this.faceRecognizeServer.isStart = config.faceRecognize.isStart
  }
  // gestureRecognize
  if (has(config, 'gestureRecognize.isStart')) {
    this.gestureRecognizeServer.isStart = config.gestureRecognize.isStart
  }
  // soundServer
  if (has(config, 'soundServer.soundsType')) {
    this.soundServer.soundsType = config.soundServer.soundsType
  }
  if (has(config, 'soundServer.isSoundOpen')) {
    this.soundServer.isSoundOpen = config.soundServer.isSoundOpen
  }
  // systemCheck
  if (has(config, 'systemCheck')) {
  }
  // animateConfig
  if (has(config, 'animateConfig.animateDebug')) {
    this.animateServer.setAnimateDebug(config.animateConfig.animateDebug)
  }
  // theme
  if (has(config, 'theme.themes')) {
    this.themeServer.callMutation('initTheme', config.theme.themes)
  }
  if (has(config, 'theme.currentThemeValue')) {
    this.themeServer.setTheme(config.theme.currentThemeValue)
  }
  // language
  if (has(config, 'language')) {
    this.languageServer.init(config.language)
  }
}
